<?php #//v.3.3.0
#///////////////////////////////////////////////////////
#//  COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED//
#///////////////////////////////////////////////////////

require('./includes/config.inc.php');

$query_settings = "select * from PHPAUCTIONXL_proxybid_settings where id='1'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $activated = mysql_result($query_settings2,0,"activated");

$query_settings3 = "select * from PHPAUCTIONXL_version_1_4 where id='1'";
                             $query_settings4 =  mysql_query ($query_settings3);
                                $autobidder_instant_death = mysql_result($query_settings4,0,"autobidder_instant_death");
                                $autobidder_activation_seconds = mysql_result($query_settings4,0,"autobidder_activation_seconds"); 
                               
                               
                               $query_settings33 = "select * from PHPAUCTIONXL_version_2_0 where id='1'";
                             $query_settings44 =  mysql_query ($query_settings33);
                                $time_reset = mysql_result($query_settings44,0,"timer_reset");
                               
                                
       $cron = 0;
    while($cron < 60) {

$TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));

$NOW = date("YmdHis",$TIME);


//* get ending soon auctions */
$TPL_ending_soon_value = "";
$query = "select retail,ends,id,title,current_high_bidder,current_bid,pict_url,ends2,reserve_price,notimer,promotion,seat_qty,seats_taken from PHPAUCTIONXL_auctions2
         WHERE closed='0' AND
         suspended='0' AND ";
         $query .= "starts<=".$NOW."
         order by ends2 LIMIT 0,100";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);

$jsenddate = "";

$jsenddate .= substr ($NOW, 4, 2);
$jsenddate .= "/";
$jsenddate .= substr ($NOW, 6, 2);
$jsenddate .= "/";
$jsenddate .= substr ($NOW, 0, 4);
$jsenddate .= " ";


     
if (substr ($NOW, 8, 2) > 12) {
$jsenddate .= substr ($NOW, 8, 2)-12;
$jsampm = "PM";
}
if (substr ($NOW, 8, 2) != 00){
if (substr ($NOW, 8, 2) < 12) {
$jsenddate .= substr ($NOW, 8, 2);
$jsampm = "AM";
}}
if (substr ($NOW, 8, 2) == 12) {
$jsenddate .= substr ($NOW, 8, 2);
$jsampm = "PM";
}
if (substr ($NOW, 8, 2) == 00) {
$jsenddate .= 12;
$jsampm = "AM";
}

$jsenddate .= ":";
$jsenddate .= substr ($NOW, 10, 2);
$jsenddate .= ":";
$jsenddate .= substr ($NOW, 12, 2);
$jsenddate .= " ";
$jsenddate .= $jsampm;
$jsenddate .= "|";

 $i = 0;
while($i < $num_auction) {

$title 	= mysql_result($result,$i,"title");
	$id 	= mysql_result($result,$i,"id");
	$ends 	= mysql_result($result,$i,"ends");
  $high_bidder 	= mysql_result($result,$i,"current_high_bidder");
	$high_bid 	= mysql_result($result,$i,"current_bid");
	$picture_url = mysql_result($result,$i,"pict_url");
	$retail  = mysql_result($result,$i,"retail");
			$reserve_price  = mysql_result($result,$i,"reserve_price");
			$notimer  = mysql_result($result,$i,"notimer");
			$promotion  = mysql_result($result,$i,"promotion");
			$seat_qty  = mysql_result($result,$i,"seat_qty");
				$seats_taken  = mysql_result($result,$i,"seats_taken");
	$nowt	= $TIME;

     #/////////////////////////////////////////////////////////////////////
#// CALCULATE SECONDS LEFT UNTIL AUCTION ENDS
#/////////////////////////////////////////////////////////////////////

$time_ends_seconds = substr ($ends, 0, 4); // Year
$time_ends_seconds .= "-";
$time_ends_seconds .= substr ($ends, 4, 2); // Month
$time_ends_seconds .= "-";
$time_ends_seconds .= substr ($ends, 6, 2); // Day
$time_ends_seconds .= " ";
$time_ends_seconds .= substr ($ends, 8, 2); // Hour
$time_ends_seconds .= ":";
$time_ends_seconds .= substr ($ends, 10, 2); // Minute
$time_ends_seconds .= ":";
$time_ends_seconds .= substr ($ends, 12, 2); // Second

   
   
   if ( $time_reset == 1 ) {
   
   if ( $reserve_price >= $high_bid ) {
   
   
          $auctionends = $ends;  
                 $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            
            if (($__END - $nowt) <= 66 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + 60, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
               
                $query3433234 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$id";
              mysql_query($query3433234);   
              
              $query34332342 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$id";
              mysql_query($query34332342);     
           
             }
   }
   
   
       }
   
   
   
   if ( $notimer == 1 ) {
   
            $notimer_reserve = $reserve_price +.01;
         if ( $notimer_reserve > $high_bid ) {
   
   
          $auctionends = $ends;  
                 $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            
            if (($__END - $nowt) <= 66 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + 60, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
               
                $query3433234 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$id";
              mysql_query($query3433234);   
              
              $query34332342 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$id";
              mysql_query($query34332342);     
           
             }
   }
   
  }  
   
   
   
   
   
   
   
   
   
   
   
   
     
   
   
   
   
   
   
   
   
$jsenddate .= $id;
	$jsenddate .= "|";
	$jsenddate .= "1";
$jsenddate .= "|";
$jsenddate .= substr ($ends, 4, 2);
$jsenddate .= "/";
$jsenddate .= substr ($ends, 6, 2);
$jsenddate .= "/";
$jsenddate .= substr ($ends, 0, 4);
$jsenddate .= " ";

if (substr ($ends, 8, 2) > 12) {
$jsenddate .= substr ($ends, 8, 2)-12;
$jsampm = "PM";
}
if (substr ($ends, 8, 2) != 00) {
if (substr ($ends, 8, 2) < 12) {
$jsenddate .= substr ($ends, 8, 2);
$jsampm = "AM";
}
}
if (substr ($ends, 8, 2) == 12) {
$jsenddate .= substr ($ends, 8, 2);
$jsampm = "PM";
}
if (substr ($ends, 8, 2) == 00) {
$jsenddate .= substr ($ends, 8, 2);
$jsampm = "AM";
}

$jsenddate .= ":";
$jsenddate .= substr ($ends, 10, 2);
$jsenddate .= ":";
$jsenddate .= substr ($ends, 12, 2);
$jsenddate .= " ";
$jsenddate .= $jsampm;
$jsenddate .= "|";
$jsenddate .= stripslashes($title);
$jsenddate .= "|";
$jsenddate .= $high_bidder;
$jsenddate .= "|";
$jsenddate .= print_money_nosymbol($high_bid);
$jsenddate .= "|";
$jsenddate .= $picture_url;
$jsenddate .= "|";
$jsenddate .= print_money_nosymbol($retail);
$jsenddate .= "|";
$jsenddate .= $promotion;
$jsenddate .= "|";
$jsenddate .= $notimer;
$jsenddate .= "|";
$jsenddate .= $seat_qty;
$jsenddate .= "|";
$jsenddate .= $seats_taken;
$jsenddate .= "|";







$i++;
}









      $myFile = "cronfiles/get_time2.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $jsenddate;
fwrite($fh, $stringData);
fclose($fh);

     
                  /*       if ( $activated == 1 ) {
              
              if ( $autobidder_instant_death == 0 ) {
include 'autobidder2cron.php';
         //echo "work";

              }
                    if ( $autobidder_instant_death == 1 ) {
include 'autobidder2croninstantdeath.php';
              }

                 }    */
  

      /*
$query_settings2 = "select * from PHPAUCTIONXL_unique_settings where id='1'";
                             $query_settings3 =  mysql_query ($query_settings2);
                                $activated2 = mysql_result($query_settings3,0,"activated");
        if ( $activated2 == 1 ) {
include 'uniquecron.php';
      }
          */
      

    /*
    
     $ProcessState = 0;
     $PID = shell_exec("nohup unique.php > /dev/null & echo $!");
     exec("ps $PID", $ProcessState);
      echo $PID;
      
      
      echo $ProcessState;
     
      if ( count($ProcessState) >= 2 )
      {
                          echo $PID;
      echo $ProcessState;
      
     if(exec::is_running($PID)){
           exec("kill -KILL $PID");      
      }
     }
           
     */      
       $cron++;  
       
       if ( $cron == 59 )
  
  {
  mysql_close($linktodatabase);
  exit;
    }
       
       sleep(1); 
               //  echo $cron;
               // echo "<BR>";
             
    }     
           
?> 